package com.project.nimsen.weixin.bean;

import java.util.ArrayList;
import java.util.List;

import org.apache.shiro.util.CollectionUtils;
import org.dom4j.Element;

/**
 * 图文列表信息
 * */
public class ImgTextSMsg extends BaseMsg {
	private List<ImgTextItem> articles = new ArrayList<ImgTextItem>();//图文列表的信息

	public void add(ImgTextItem item) {
		articles.add(item);
	}
	protected String info() {
		StringBuffer info = new StringBuffer();
		if(CollectionUtils.isEmpty(articles))
			return info.toString();
		
		info.append("<ArticleCount>").append(articles.size()).append("</ArticleCount>");
		info.append("<Articles>");
		
		for(ImgTextItem item : articles){
			info.append(item.toString());
		}
		info.append("</Articles>");
		return info.toString();
	}
	
	public ImgTextItem initItem(){
		return new ImgTextItem();
	}
	/**
	 * 图文列表里每个图文的信息
	 * */
	public class ImgTextItem{
		public ImgTextItem(){}
		private String title;//图文消息标题
		private String description;//图文消息描述
		private String picUrl;//图片链接，支持JPG、PNG格式，较好的效果为大图360*200，小图200*200
		private String url;//点击图文消息跳转链接
		public String getTitle() {
			return title;
		}
		public void setTitle(String title) {
			this.title = title;
		}
		public String getDescription() {
			return description;
		}
		public void setDescription(String description) {
			this.description = description;
		}
		public String getPicUrl() {
			return picUrl;
		}
		public void setPicUrl(String picUrl) {
			this.picUrl = picUrl;
		}
		public String getUrl() {
			return url;
		}
		public void setUrl(String url) {
			this.url = url;
		}
		public String toString() {
			StringBuffer str = new StringBuffer();
			str.append("<item>");
			
			str.append("<Title><![CDATA[").append(this.getTitle()).append("]]></Title>");
			str.append("<Description><![CDATA[").append(this.getDescription()).append("]]></Description>");
			str.append("<PicUrl><![CDATA[").append(this.getPicUrl()).append("]]></PicUrl>");
			str.append("<Url><![CDATA[").append(this.getUrl()).append("]]></Url>");
			
			str.append("</item>");
			return str.toString();
		}
	}
	protected void fullchildProperty(Element root) {
		//这里是发送信息的类所以不需要从xml转换为实体类
	}
}
